import MarkdownIt from "markdown-it";
import markdownQuote from "markdown-it-quote";
import markdownkatex from "@vscode/markdown-it-katex";
import hljs from "highlight.js";
import katex from "katex";
import "katex/contrib/mhchem";
import "katex/contrib/copy-tex";

const md = new MarkdownIt({
  highlight: function (str, lang) {
    if (lang && hljs.getLanguage(lang)) {
      return (
        '<pre class="hljs"><code>' +
        hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
        "</code></pre>"
      );
    }

    return (
      '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + "</code></pre>"
    );
  },
});
md.use(markdownQuote);
md.use(markdownkatex, { katex });

export default md;
